<?php 
$this->Html->css('schedule','stylesheet', array('inline' => false ) );
if($intBWMode==1)
{
	$this->Html->css('schedule_bw','stylesheet', array('inline' => false ) );
}
$intOffset = 39;
echo '<div align="right">';
if($strDisplayMode == "full")
{
	if($intBWMode == 0)
	{
		echo '<a href='.$this->Html->url(array( "controller" => "schedules", "action" => "index", "compact", "0", $strExtendedOptions)).'>selektywny</a> | '.
			 '<a href='.$this->Html->url(array( "controller" => "schedules", "action" => "index", "full", "1", $strExtendedOptions)).'>cz/b do druku</a> ';
	}
	else
	{
		echo '<a href='.$this->Html->url(array( "controller" => "schedules", "action" => "index", "compact", "1", $strExtendedOptions)).'>selektywny</a> | '.
			 '<a href='.$this->Html->url(array( "controller" => "schedules", "action" => "index", "full", "0", $strExtendedOptions)).'>wersja kolorowa</a> ';
	}
}
else
{
	if($intBWMode == 0)
	{
		echo '<a href='.$this->Html->url(array( "controller" => "schedules", "action" => "index", "full", "0", $strExtendedOptions)).'>pełny</a> | '.
			 '<a href='.$this->Html->url(array( "controller" => "schedules", "action" => "index", "compact", "1", $strExtendedOptions)).'>cz/b do druku</a> ';

	}
	else
	{
		echo '<a href='.$this->Html->url(array( "controller" => "schedules", "action" => "index", "full", "1", $strExtendedOptions)).'>pełny</a> | '.
			 '<a href='.$this->Html->url(array( "controller" => "schedules", "action" => "index", "compact", "0", $strExtendedOptions)).'>wersja kolorowa</a> ';

	}
}
echo '</div>';
echo '<div class="scheduleHeader">Plan dla kierunku: <b>'.$strCourseName.'</b>,
	 tryb: <b>'.$strMode.'</b>, 
	 semestr: <b>'.$data[0]['Schedule']['semester'].'</b> 
	 z <b>'.$data[0]['Schedule']['date'].'</b>
	 tydzień: <b>'.(date("W")-$intOffset).'</b></div>';

 echo '<table cellspacing="1" cellpadding="1" border="0" align="center">
<tbody>
<tr>
<td class="planPoleGodzinyGorne">&nbsp;</td>
<td class="planPoleGodzinyGorne" align="center" colspan="2">8:45</td>
<td class="planPoleGodzinyGorne" align="center" colspan="2">10:25</td>
<td class="planPoleGodzinyGorne" align="center" colspan="2">12:05</td>
<td class="planPoleGodzinyGorne" align="center" colspan="2">13:45</td>
<td class="planPoleGodzinyGorne" align="center" colspan="2">15:25</td>
<td class="planPoleGodzinyGorne" align="center" colspan="2">17:05</td>
<td class="planPoleGodzinyGorne" align="center" colspan="2">18:45</td>
<td class="planPoleGodzinyGorne" align="center" colspan="2">20:25</td>
</tr>
<tr>
<td class="planPoleGodzinyLewe">7:15</td>
<td class="planPoleGodzinyLewe">8:00</td>
<td class="planPoleGodzinyPrawe">9:30</td>
<td class="planPoleGodzinyLewe">9:40</td>
<td class="planPoleGodzinyPrawe">11:10</td>
<td class="planPoleGodzinyLewe">11:20</td>
<td class="planPoleGodzinyPrawe">12:50</td>
<td class="planPoleGodzinyLewe">13:00</td>
<td class="planPoleGodzinyPrawe">14:30</td>
<td class="planPoleGodzinyLewe">14:40</td>
<td class="planPoleGodzinyPrawe">16:10</td>
<td class="planPoleGodzinyLewe">16:20</td>
<td class="planPoleGodzinyPrawe">17:50</td>
<td class="planPoleGodzinyLewe">18:00</td>
<td class="planPoleGodzinyPrawe">19:30</td>
<td class="planPoleGodzinyLewe">19:40</td>
<td class="planPoleGodzinyPrawe">21:10</td>
</tr>';
$intArrPosition = 0;
$intCount = 0;
$intPosition = 1;
$intDay = 1;
$intRow = 1;
$blnGo = true;

while($blnGo == true) {
	

	if($intPosition==1)
	{
		if(isset($data[$intArrPosition]['Classe']['day_id']) && $data[$intArrPosition]['Classe']['day_id']>=$intDay+1)
		{
			$intDay=$data[$intArrPosition]['Classe']['day_id'];
		
		}
		if($intRow == 1)
		{
		echo'<tr><td class="scheduleDayHeader" colspan="17">'.$arrDays[$intDay-1]['Day']['name'].'</td></tr>';
		}
		echo'<tr>';
	}
	if(isset($data[$intArrPosition]) &&
		$data[$intArrPosition]['Classe']['day_id']==$intDay &&
		$data[$intArrPosition]['Classe']['row']==$intRow &&
		$data[$intArrPosition]['Classe']['position']==$intPosition &&
		!isset($data[$intArrPosition]['Classe']['skip']))
	{
		if(!empty($data[$intArrPosition]['Classe']['selective_weeks']))
		{
			$data[$intArrPosition]['Classe']['week_type'].=' tw';
		}
		echo '<td class="scheduleFull '.$data[$intArrPosition]['Classe']['week_type'].'" colspan="'.
			 $data[$intArrPosition]['Classe']['length'].'" title="'.
			 $data[$intArrPosition]['Classe']['full_name'].'">
		<span class="class_group">'.$data[$intArrPosition]['Classe']['group'].'</span>
		<span class="short_name">'.$data[$intArrPosition]['Classe']['short_name'].'</span>
		<span class="full_name">'.$data[$intArrPosition]['Classe']['full_name'].'</span>
		<span class="instructor">'.$data[$intArrPosition]['Classe']['instructor'].'</span>
		<span class="room_no">'.$data[$intArrPosition]['Classe']['room_no'].'</span>
		<span class="selective_weeks">'.$data[$intArrPosition]['Classe']['week_type'].', '.$data[$intArrPosition]['Classe']['selective_weeks'].'</span>
		</td>';
		
		$intPosition+=$data[$intArrPosition]['Classe']['length'];
		$intArrPosition++;
	}
	elseif(isset($data[$intArrPosition]['Classe']['skip']) && $data[$intArrPosition]['Classe']['skip']==true)
	{
		$intArrPosition++;
		
	}
	else
	{
		$blnInsert = false;
		$intArrNewPosition = $intArrPosition;
		while((isset($data[$intArrNewPosition]['Classe']['day_id'])) && ($data[$intArrNewPosition]['Classe']['day_id']==$intDay) && ($blnInsert == false))
		{
			if($data[$intArrNewPosition]['Classe']['position']==$intPosition && (($data[$intArrNewPosition]['Classe']['position']+$data[$intArrNewPosition]['Classe']['length'] <= $data[$intArrPosition]['Classe']['position'] && $data[$intArrPosition]['Classe']['row'] == $intRow) || $data[$intArrPosition]['Classe']['row'] != $intRow))
			{
				if(!empty($data[$intArrNewPosition]['Classe']['selective_weeks']))
				{
					$data[$intArrNewPosition]['Classe']['week_type'].=' tw';
				}
				echo'<td class="scheduleFull '.$data[$intArrNewPosition]['Classe']['week_type'].'" colspan="'.$data[$intArrNewPosition]['Classe']['length'].'" title="'.$data[$intArrNewPosition]['Classe']['full_name'].'">
		<span class="class_group">'.$data[$intArrNewPosition]['Classe']['group'].'</span>
		<span class="short_name">'.$data[$intArrNewPosition]['Classe']['short_name'].'</span>
		<span class="full_name">'.$data[$intArrNewPosition]['Classe']['full_name'].'</span>
		<span class="instructor">'.$data[$intArrNewPosition]['Classe']['instructor'].'</span>
		<span class="room_no">'.$data[$intArrNewPosition]['Classe']['room_no'].'</span>
		<span class="selective_weeks">'.$data[$intArrNewPosition]['Classe']['week_type'].', '.$data[$intArrNewPosition]['Classe']['selective_weeks'].'</span>
		</td>';
					
				$intPosition+=$data[$intArrNewPosition]['Classe']['length']-1;
				$blnInsert = true;
				$data[$intArrNewPosition]['Classe']['skip'] = true;
				//debug('kupa');
			}
			
			$intArrNewPosition++;
		}
		///debug($intArrNewPosition);
		///debug($intArrPosition);
		if(!$blnInsert)
		{
			echo'<td class="scheduleEmpty"></td>';
		}
		$intPosition++;
	}

	if($intPosition>=18)
	{
		$intPosition=1;
		if(isset($data[$intArrPosition]) && $data[$intArrPosition]['Classe']['day_id']>$intDay)
		{
			$intDay++;
			$intRow=1;
		}
		else {
			$intRow++;
			
		}
		echo'</tr>';
		if(!isset($data[$intArrPosition])){
			$blnGo = false;
		}			
	}



	$intCount++;
	if($intCount==350)
	{
		$blnGo = false;
	}
}
	
	
/*	
	if(isset($data[$intCount]['Classe']['day_id']) =='Poniedzialek')
	{
		
		echo'<tr><td class="scheduleDayHeader" colspan="17">Poniedziałek</td></tr>';


	} elseif(isset($schedule[$intCount][0]) && $schedule[$intCount][0]=='Wtorek')
	{
		echo'<tr><td class="scheduleDayHeader" colspan="17">Wtorek</td></tr>';
		$intPosition = 0;
		$intDay = 2;
		$intRow = 1;
	}elseif(isset($schedule[$intCount][0]) && $schedule[$intCount][0]=='Sroda')
	{
		echo'<tr><td class="scheduleDayHeader" colspan="17">Środa</td></tr>';
		$intPosition = 0;
		$intDay = 3;
		$intRow = 1;
	}elseif(isset($schedule[$intCount][0]) && $schedule[$intCount][0]=='Czwartek')
	{
		echo'<tr><td class="scheduleDayHeader" colspan="17">Czwartek</td></tr>';
		$intPosition = 0;
		$intDay = 4;
		$intRow = 1;
	}elseif(isset($schedule[$intCount][0]) && $schedule[$intCount][0]=='Piatek')
	{
		echo'<tr><td class="scheduleDayHeader" colspan="17">Piątek</td></tr>';
		$intPosition = 0;
		$intDay = 5;
		$intRow = 1;
	}elseif(isset($schedule[$intCount][0]) && $schedule[$intCount][0]=='Sobota')
	{
		echo'<tr><td class="scheduleDayHeader" colspan="17">Sobota</td></tr>';
		$intPosition = 0;
		$intDay = 6;
		$intRow = 1;
	}elseif(isset($schedule[$intCount][0]) && $schedule[$intCount][0]=='Niedziela')
	{
		echo'<tr><td class="scheduleDayHeader" colspan="17">Niedziela</td></tr>';
		$intPosition = 0;
		$intDay = 7;
		$intRow = 1;
	}elseif(isset($schedule[$intCount][1]))
	{
		if($intPosition>=17)
		{
			echo'</tr>';
		}elseif($intPosition==0)
		{
			echo'<tr>';
		
		}
		echo'<td class="scheduleFull';
		if ($schedule[$intCount][6]=="tz, " || $schedule[$intCount][7] == "tz")
		{
			if($schedule[$intCount][6]=="tz, ")
			{
				echo ' tw';
			}
			echo ' tz';
		}
		elseif($schedule[$intCount][6]=="tp, " || $schedule[$intCount][7] == "tp")
		{
			if($schedule[$intCount][6]=="tp, ")
			{
				echo ' tw';
			}
			echo ' tp';
		}
		elseif($schedule[$intCount][6]=="tn, " || $schedule[$intCount][7] == "tn")
		{
			if($schedule[$intCount][6]=="tn, ")
			{
				echo ' tw';
			}
			echo ' tn';
		}
		echo'" colspan="'.$schedule[$intCount][2].'">'.iconv("CP1250", "UTF-8",$schedule[$intCount][3]).'</td>';
		//debug("$intDay, $intRow, $intPosition, ".iconv("ISO-8859-2", "UTF-8",$schedule[$intCount][3]));
		$intPosition+=$schedule[$intCount][2]-1;
	}else{
		if($intPosition>=17)
		{
			echo'<td class="scheduleEmpty"></td></tr>';
		}elseif($intPosition==0)
		{
			echo'<tr><td class="scheduleEmpty"></td>';
		
		}else {
			echo'<td class="scheduleEmpty"></td>';
			
		}
		
		
	}
	if($intPosition>=17)
	{
		$intPosition = 0;
		$intRow++;
		//echo'</tr>';
	}elseif($intPosition==0)
	{
		//echo'<tr>';
		
	}
	$intPosition++;
	$intCount++;
}*/
echo '</table>';
?>